package com.zy.web.demo.wenjian;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class readFile {

    public static void main(String[] args) {
        // 读取文件内容public String readFile(){
        String path = "C:\\Users\\pc\\Desktop\\java.txt";
        File file = new File(path);
        List<String> list = new LinkedList<>();
        try{
            //构造一个BufferedReader类来读取文件
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            String s = null;
            String pattern = "(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]";
            Pattern p = Pattern.compile(pattern);
            while((s = br.readLine())!=null){//使用readLine方法，一次读一行
                String[] split = s.split("/");
                list.add(split[0]+"//"+split[1]+split[2]);
            }

            List<String> collect = list.stream().distinct().collect(Collectors.toList());
            for (String s1 : collect) {
                System.out.println(s1.split("~~")[0]);
            }
            br.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }

}
